package com.tcm.core.service;

import com.base.core.dozer.DozerConvert;
import com.base.core.utils.JacksonUtils;
import com.base.core.utils.ListUtils;
import com.base.genid.generator.UidGenerator;
import com.tcm.core.domain.dto.FeedbackDTO;
import com.tcm.core.domain.entity.Feedback;
import com.tcm.core.mapper.FeedbackMapper;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;

@DubboService(version = "0.0.1-alpha", retries = 3, timeout = 3000)
public class FeedbackServiceImpl implements FeedbackService {

    @Autowired
    private FeedbackMapper feedbackMapper;

    @DubboReference(version = "0.0.1-beta", group = "cached-uid", check = false, retries = 3)
    private UidGenerator uidGenerator;


    /**
     * 新增
     *
     * @param feedbackDto
     * @throws Exception
     */
    @Override
    public void save(FeedbackDTO feedbackDto) throws Exception {


        Feedback feedback = DozerConvert.copyProperties(feedbackDto, Feedback.class);
        List<String> imgArr = feedbackDto.getImgArr();
        if (ListUtils.isNotEmpty(imgArr)) {
            feedback.setImages(JacksonUtils.toJSONString(imgArr));
        }
        feedback.setId(uidGenerator.getUID());
        feedback.setCreateTime(LocalDateTime.now());
        feedback.setUpdateTime(LocalDateTime.now());
        feedback.setDeleted(new Byte("0"));
        feedbackMapper.insert(feedback);
    }

}
